import { ElLoading } from "element-plus";

let loadingInstance: ReturnType<typeof ElLoading.service>


const startLoading = () => {
    loadingInstance = ElLoading.service({
        fullscreen: true,
        lock: true,
        text: "Loading",
        background: "rgba(0, 0, 0, 0.7)"
    })
}

//请求个数
let requestNumber = 0

//开启全屏加载
export const showFullLoading = () => {
    if (requestNumber == 0) {
        startLoading()
    }
    requestNumber++
}

//隐藏全屏加载
export const hideFullLoading = () => {
    if (requestNumber <= 0) return
    requestNumber--
    if (requestNumber == 0) {
        loadingInstance.close()
    }

}